cd "D:\Dropbox\book_welfare\replication"

************************************************
* coefficient by genre figure: Bookstat 
************************************************	




* genre 


use data\bookstat_gender_pyear_genre_asin.dta, clear
 

		collapse (sum) males=N_male name_present=N_name total, by(pyear genre)
		tempfile number
		save `number'
	
use  data\bookstat_sales_gender_pyear_genre_asin.dta, clear 

		collapse (sum) q qm=q_male qname=q_name, by(pyear year genre)
		merge m:1 pyear genre  using `number'
		
		
	 * of those with identification
		gen rv_in =  (name_present - males)/name_present 	
		gen sf_in = (qname - qm)/qname
					

	* known women over total (conservative )
		gen rv_all = (name_present - males)/total 
		gen sf_all = (qname - qm)/q 

		keep if year>=2018 & year<=2021 
		keep if pyear>=1960 & pyear<=2021 		

		keep if pyear>=1960


		label var sf_in "share of vintage sales (in)"
		label var rv_in "female-authored share of new products (in)"

		egen Q=sum(q), by(genre)
		gen genre1=genre 
		replace genre1 = "other" if Q<2.5e+07


preserve 
		egen gno=group(genre1)
		collapse (mean) gno, by(genre1) 
		tempfile genre 
		save `genre'
restore 

	
egen gno=group(genre1)


* in 
reghdfe sf_in i.gno#c.rv_in, absorb(year gno pyear) 
 preserve 


	parmest, norestore 


	split parm, parse(".gno#c." "b.gno#c.")
	gen gno=real(parm1)
	drop if gno==. 

	merge 1:1 gno using `genre'

	drop if estimate==.


	graph bar (mean) estimate, over(genre1, sort(estimate) descending label(angle(forty_five) labsize(vsmall))) scheme(lean2) yline(1) ytitle(sales coefficient)


	gsort -estimate 
	gen order=_n 
	br 
	

	twoway (scatter estimate order) (rcap max95 min95 order), yline(1) scheme(lean2) legend(off)  ///
	xlabel( 1	"Children's Books" ///
2	"Crafts, Hobbies & Home" ///
3	"Religion & Spirituality" ///
4	"Kindle eBooks" ///
5	"Literature & Fiction" ///
6	"Textbooks" ///
7	"Health, Fitness & Dieting" ///
8	"Self-Help" ///
9	"Christian Books & Bibles" ///
10	"Humor & Entertainment" ///
11	"Teen & Young Adult" ///
12	"other" ///
13	"Arts & Photography" ///
14	"Education & Teaching" ///
15	"History" ///
16	"Romance" ///
17	"Comics & Graphic Novels" ///
18	"Reference" ///
19	"Mystery, Thriller & Suspense" ///
20	"Science Fiction & Fantasy" ///
21	"Business & Money" ///
22	"Biographies & Memoirs" ///
23	"Medical Books" ///
24	"Science & Math" ///
25	"Politics & Social Sciences" ///
26	"Cookbooks, Food & Wine" , labsize(vsmall) angle(forty_five) noticks) xtitle("") t1("genre, vintage, and year FE") ytitle(sales coefficient) t1(among identified)
	graph export latex_text\figures\sales_wrt_nf_by_genre_in_asin.pdf, as(pdf) name("Graph") replace 



restore 

* all 

reghdfe sf_all i.gno#c.rv_all, absorb(year gno pyear) 




 preserve 


	parmest, norestore 


	split parm, parse(".gno#c." "b.gno#c.")
	gen gno=real(parm1)
	drop if gno==. 

	merge 1:1 gno using `genre'

	drop if estimate==.


	graph bar (mean) estimate, over(genre1, sort(estimate) descending label(angle(forty_five) labsize(vsmall))) scheme(lean2) yline(1) ytitle(sales coefficient)


	gsort -estimate 
	gen order=_n 
	

	twoway (scatter estimate order) (rcap max95 min95 order), yline(1) scheme(lean2) legend(off)  ///
	xlabel( 1	"Children's Books" ///
2	"Crafts, Hobbies & Home" ///
3	"Religion & Spirituality" ///
4	"Literature & Fiction" ///
5	"Kindle eBooks" ///
6	"Christian Books & Bibles" ///
7	"Textbooks" ///
8	"Health, Fitness & Dieting" ///
9	"Self-Help" ///
10	"History" ///
11	"Romance" ///
12	"Humor & Entertainment" ///
13	"Education & Teaching" ///
14	"Arts & Photography" ///
15	"Teen & Young Adult" ///
16	"other" ///
17	"Reference" ///
18	"Mystery, Thriller & Suspense" ///
19	"Science Fiction & Fantasy" ///
20	"Business & Money" ///
21	"Comics & Graphic Novels" ///
22	"Biographies & Memoirs" ///
23	"Medical Books" ///
24	"Science & Math" ///
25	"Cookbooks, Food & Wine" ///
26	"Politics & Social Sciences"  , labsize(vsmall) angle(forty_five) noticks) xtitle("") t1("genre, vintage, and year FE") ytitle(sales coefficient) t1(among all)
	graph export latex_text\figures\sales_wrt_nf_by_genre_all_asin.pdf, as(pdf) name("Graph") replace 


restore 




	
************************************************
* coefficient by genre figure: Goodreads 
************************************************	




use data\books_year.dta, clear  


		keep if year>=2007 & year<=2016
		keep if pubyr >=1960 & pubyr<=2016 
		replace fbookp=2 if fbookp==.
		collapse (count) n=q , by(pubyr fbookp genre1 )
		tempfile gr 
		save `gr'



use data\books_year.dta, clear  


		keep if year>=2007 & year<=2016
		keep if pubyr >=1960 & pubyr<=2016 
	
		replace fbookp=2 if fbookp==.

		collapse (sum) qf qm q qc* , by(year pubyr fbookp genre1 )

		merge m:1 pubyr fbookp genre1 using `gr'

		egen gno=group(genre1)
		
		
		egen Qv_all = sum(q), by(genre1 pubyr year)
		gen sv_all=q/Qv_all
		
		egen Nv_all = sum(n), by(genre1 pubyr year)
		gen rv_all = n/Nv_all

		egen Qv_in = sum(q) if fbookp<2, by(genre1 pubyr year)
		gen sv_in=q/Qv_in
	
		egen Nv_in = sum(n) if fbookp<2, by(genre1 pubyr year)
		gen rv_in = n/Nv_in
		
		
		
		egen QFv = sum(qf), by(genre1 pubyr year)
		gen sfv=qf/QFv
		egen QMv = sum(qm), by(genre1 pubyr year)
		gen smv=qm/QMv


	
		egen N=sum(n), by(pubyr) 

		label var sv_in "female-authored share of consumption (in)"
		label var rv_in "female-authored share of new products (in)"
			
		label var sv_all "female-authored share of consumption (all)"
		label var rv_all  "female-authored share of new products (all)"
		label var sfv "fem-auth shr of female cons"
		label var smv "fem-auth shr of male cons"

	 
 

preserve 
	collapse (mean) gno, by(genre) 
	tempfile genre 
	save `genre'
restore 
 

 
*in  - all users 
preserve 
	reghdfe sv_in i.gno#c.rv_in if fbookp==1 , absorb(gno year pubyr)  

	parmest, norestore 
		
	split parm, parse(".gno#c." "b.gno#c.")
	gen gno=real(parm1)
	drop if gno==. 

	merge 1:1 gno using `genre'


	graph bar (mean) estimate, over(genre, sort(estimate) descending label(angle(forty_five) labsize(vsmall))) scheme(lean2) yline(1) ytitle(sales coefficient)




	gsort -estimate 
	gen order=_n 
	twoway (scatter estimate order) (rcap max95 min95 order), yline(1) scheme(lean2) legend(off)  ///
	xlabel(   1 "young-adult" ///
	  2 "romance" /// 
	  3 "fantasy" /// 
	  4 "mystery" ///
	  5 "missing" ///
	  6 "history" ///
	  7 "non-fiction" ///
	  8 "fiction" ///
	  9 "poetry" ///
	 10 "children" ///
	 11 "comics"  , labsize(small) angle(forty_five) noticks) xtitle("") t1("genre, vintage, and year FE") ytitle(sales coefficient) t1(among identified)



	graph export latex_text\figures\sales_wrt_nf_by_genre_gr_in.pdf, as(pdf) name("Graph") replace 






gsort -estimate 
drop order
gen order=_n 
twoway (scatter estimate order) (rcap max95 min95 order), yline(1) scheme(lean2) legend(off)  ///
xlabel(   1 "young-adult" ///
  2 "romance" /// 
  3 "fantasy" /// 
  4 "mystery" ///
  5 "missing" ///
  6 "history" ///
  7 "non-fiction" ///
  8 "fiction" ///
  9 "poetry" ///
 10 "children" ///
 11 "comics"  , labsize(small) angle(forty_five) noticks) xtitle("") t1("genre, vintage, and year FE") ytitle(sales coefficient) t1(among identified)



graph export latex_text\figures\sales_wrt_nf_by_genre_gr_in.pdf, as(pdf) name("Graph") replace 

restore 

******************************************
******************************************
* all  
 preserve 
reghdfe sv_all i.gno#c.rv_all if fbookp==1 , absorb(gno year pubyr)  

parmest, norestore 
	
split parm, parse(".gno#c." "b.gno#c.")
gen gno=real(parm1)
drop if gno==. 

merge 1:1 gno using `genre'


graph bar (mean) estimate, over(genre, sort(estimate) descending label(angle(forty_five) labsize(vsmall))) scheme(lean2) yline(1) ytitle(sales coefficient)




gsort -estimate 
gen order=_n 

twoway (scatter estimate order) (rcap max95 min95 order), yline(1) scheme(lean2) legend(off)  ///
xlabel(  1 "children"  2 "comics"  3  "history"  4  "young-adult" 5  "fantasy" 6  "fiction"  7  "missing"   8  "poetry"  9  "non-fiction" 10   "romance" 11 "mystery"   , labsize(small) angle(forty_five) noticks) xtitle("") t1("genre, vintage, and year FE") ytitle(sales coefficient) t1(among all)

  


graph export latex_text\figures\sales_wrt_nf_by_genre_gr_all.pdf, as(pdf) name("Graph") replace 

restore 


